<?php
namespace app\index\controller;

use app\common\model\PieceShare;
use app\common\model\Product as ProductModel;
use app\common\model\ProductPiece;

class Index extends BaseController
{
    public function index(){
        if($share_id = input('share_id')){//检查是不是分享碎片页面进入的
            $this->assign('is_share',true);
            //检查碎片是否已经被领取完
            $share_data = PieceShare::get($share_id);
            $share_data = $share_data->toArray();
            if(!$share_data['is_received']){//如果没领
                $piece = ProductPiece::getById($share_data['piece_id']);
                $this->assign('share_data',$share_data);
                $this->assign('share_piece',$piece->toArray());
            }else{//提示已领取

            }
            $this->assign('is_received',$share_data['is_received']);
        }
        //如果不是分享页面进入，直接显示首页
        //公共数据
        $products = ProductModel::getAll();
        $products = collection($products)->toArray();
        $this->assign('products',$products);
       return  $this->fetch();
    }
}
